﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="omandiOsadType_v4", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(OmandiOsadTypeV4))]
    public class OmandiOsadTypeV4Serializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IOmandiOsadTypeV4 clazz;
        
        public OmandiOsadTypeV4Serializer(IOmandiOsadTypeV4 clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("tegevus");
            if (clazz.Tegevus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tegevus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tegevus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("liik");
            if (clazz.Liik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Liik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Liik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("sissemaksu_summa");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.SissemaksuSumma))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("sissemaksu_valuuta");
            if (clazz.SissemaksuValuuta!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SissemaksuValuuta))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SissemaksuValuuta");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("omandiliik");
            if (clazz.Omandiliik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Omandiliik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Omandiliik");
            }
            Writer.WriteEndElement();
            if (clazz.HyLiikmesusNumber!=null) {
                Writer.WriteStartElement("hy_liikmesus_number");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.HyLiikmesusNumber))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.HyLiikmesusPindala!=null) {
                Writer.WriteStartElement("hy_liikmesus_pindala");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.HyLiikmesusPindala))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.HyLiikmesusMaksumaarLugeja!=null) {
                Writer.WriteStartElement("hy_liikmesus_maksumaar_lugeja");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.HyLiikmesusMaksumaarLugeja))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.HyLiikmesusMaksumaarNimetaja!=null) {
                Writer.WriteStartElement("hy_liikmesus_maksumaar_nimetaja");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.HyLiikmesusMaksumaarNimetaja))).ToString());
                Writer.WriteEndElement();
            }
            for (int x = 0; ((clazz.Isikud != null) 
                        && (x < clazz.Isikud.Count)); x = (x + 1)) {
                if (clazz.Isikud[x]!=null) {
                    Writer.WriteStartElement("isikud");
                    global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData(clazz.Isikud[x]);
                    Writer.WriteTypeAttribute(metaIsikud.TypeQualifiedName.Namespace, metaIsikud.TypeQualifiedName.Name);
                    metaIsikud.NewSerializer(clazz.Isikud[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
            for (int x = 0; ((clazz.OsaKitsendused != null) 
                        && (x < clazz.OsaKitsendused.Count)); x = (x + 1)) {
                if (clazz.OsaKitsendused[x]!=null) {
                    Writer.WriteStartElement("osa_kitsendused");
                    global::Xtee.Core.SerializationMetadata metaOsaKitsendused = this.GetMetaData(clazz.OsaKitsendused[x]);
                    Writer.WriteTypeAttribute(metaOsaKitsendused.TypeQualifiedName.Namespace, metaOsaKitsendused.TypeQualifiedName.Name);
                    metaOsaKitsendused.NewSerializer(clazz.OsaKitsendused[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="tegevus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omandiOsadType_v4>tegevus");
                }
                clazz.Tegevus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tegevus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>omandiOsadType_v4>tegevus", Reader.LocalName);
            }
            if (Reader.LocalName=="liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omandiOsadType_v4>liik");
                }
                clazz.Liik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("liik")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>omandiOsadType_v4>liik", Reader.LocalName);
            }
            if (Reader.LocalName=="sissemaksu_summa") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omandiOsadType_v4>sissemaksu_summa");
                }
                clazz.SissemaksuSumma = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("sissemaksu_summa")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>omandiOsadType_v4>sissemaksu_summa", Reader.LocalName);
            }
            if (Reader.LocalName=="sissemaksu_valuuta") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omandiOsadType_v4>sissemaksu_valuuta");
                }
                clazz.SissemaksuValuuta = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("sissemaksu_valuuta")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>omandiOsadType_v4>sissemaksu_valuuta", Reader.LocalName);
            }
            if (Reader.LocalName=="omandiliik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omandiOsadType_v4>omandiliik");
                }
                clazz.Omandiliik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("omandiliik")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>omandiOsadType_v4>omandiliik", Reader.LocalName);
            }
            if (Reader.LocalName=="hy_liikmesus_number") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omandiOsadType_v4>hy_liikmesus_number");
                }
                clazz.HyLiikmesusNumber = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("hy_liikmesus_number")).Value;
            }
            if (Reader.LocalName=="hy_liikmesus_pindala") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omandiOsadType_v4>hy_liikmesus_pindala");
                }
                clazz.HyLiikmesusPindala = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("hy_liikmesus_pindala")).Value;
            }
            if (Reader.LocalName=="hy_liikmesus_maksumaar_lugeja") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omandiOsadType_v4>hy_liikmesus_maksumaar_lugeja");
                }
                clazz.HyLiikmesusMaksumaarLugeja = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("hy_liikmesus_maksumaar_lugeja")).Value;
            }
            if (Reader.LocalName=="hy_liikmesus_maksumaar_nimetaja") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omandiOsadType_v4>hy_liikmesus_maksumaar_nimetaja");
                }
                clazz.HyLiikmesusMaksumaarNimetaja = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("hy_liikmesus_maksumaar_nimetaja")).Value;
            }
            if (Reader.LocalName=="isikud") {
                clazz.Isikud = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IIsikTypeV4>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "isikud")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>omandiOsadType_v4>isikud");
                    }
                    global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IIsikTypeV4>(Reader, "isikType_v4", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                    global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IIsikTypeV4 item = metaIsikud.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IIsikTypeV4>();
                    clazz.Isikud.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("isikud");
                        metaIsikud.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
            }
            if (Reader.LocalName=="osa_kitsendused") {
                clazz.OsaKitsendused = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IOsaKitsendusedTypeV4>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "osa_kitsendused")); ) {
                    if ((Reader.IsElementNil() == false)) {
                        global::Xtee.Core.SerializationMetadata metaOsaKitsendused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IOsaKitsendusedTypeV4>(Reader, "osa_kitsendusedType_v4", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IOsaKitsendusedTypeV4 item = metaOsaKitsendused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IOsaKitsendusedTypeV4>();
                        clazz.OsaKitsendused.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("osa_kitsendused");
                            metaOsaKitsendused.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    else {
                        clazz.OsaKitsendused.Add(null);
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
